package com.niiwoo.civet.trade.service.local.newRefund.penalty;

import com.niiwoo.civet.trade.enums.TradeConfigEnum;
import com.niiwoo.civet.trade.service.local.configure.TradeConfigLocalService;
import com.niiwoo.tripod.provider.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * Created by bincun on 2018/4/24.
 */
@Service
@Slf4j
public class PenaltyRateService {
    @Autowired
    private TradeConfigLocalService tradeConfigLocalService;

    private BigDecimal maxPenaltyRate;


    /**
     * 取罚息上限利率
     * @return
     */
    public BigDecimal getMaxPenaltyRate(){
        if (this.maxPenaltyRate == null){
            String maxRateStr = tradeConfigLocalService.selectTradeConfigByEmun(TradeConfigEnum.PENALTY_FEE_MAX_VALUE);
            if (StringUtils.isNumeric(maxRateStr)){
                this.maxPenaltyRate = new BigDecimal(maxRateStr).multiply(new BigDecimal("0.01")).setScale(4,BigDecimal.ROUND_HALF_UP);
            }else {
                throw new BizException("TRD_800004");
            }
        }
        return this.maxPenaltyRate;
    }
}
